package com.sk.coin.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sk.coin.sys.entity.SysRole;
import com.sk.coin.sys.mapper.SysRoleMapper;
import com.sk.coin.sys.service.ISysRoleService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 角色 服务实现类
 * </p>
 *
 * @author Administrator
 * @since 2022-02-21
 */
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole> implements ISysRoleService {

    @Override
    public boolean isSuperAdmin(Long userId) {
        String roleCode = baseMapper.getUserRoleCode(userId);
        if ("ROLE_ADMIN".equals(roleCode)) {
            return true;
        }
        return false;
    }

    @Override
    public Page<SysRole> findByPage(Page<SysRole> page, String name) {
        return page(page,new LambdaQueryWrapper<SysRole>()
                .like(StringUtils.isNoneBlank(name),SysRole::getName,name));
    }
}
